/**
 * Copyright (c) 2014 zhenrongbao.com, Inc. All Rights Reserved
 * @author: jiangshuguang
 * @Date  : 14-10-4
 * @Time  : 下午12:19
 * @brief :
 */
exports.execute = function(){

   var $widget = $(".widget-user-voice"),
       $leftBtn = $widget.find(".btn-left"),
       $rightBtn = $widget.find(".btn-right"),
       $sliderGroup = $widget.find(".slider-group");

    var index = 1,
        interval;

    function sliderLeft(){
        $sliderGroup.animate({"left":"-800"},500);
        index = 2;
    }

    function sliderRight(){
        $sliderGroup.animate({"left":"0"},500);
        index = 1;
    }

    function slider(){
        if(index==1){
            sliderLeft();
        }else if(index == 2){
            sliderRight();
        }
    }

    function play(){
        interval = setInterval(function(){
            slider();
        },3000);
    }

    function stopPlay(){
        if(interval){
            clearInterval(interval);
            interval = 0;
        }
    }

    $leftBtn.on("click",function(){
        if(index==2){
            sliderRight();
        }
    });

    $rightBtn.on("click",function(){
        if(index == 1){
            sliderLeft();
        }
    });

    $widget.on("mouseover",function(){
        stopPlay();
    }).on("mouseout",function(){
            play();
        });

   play();
};